﻿namespace Chain.IDAL
{
    using Chain.DBUtility;
    using Chain.Model;
    using System;
    using System.Collections;
    using System.Data;
    using System.Data.SqlClient;
    using System.Runtime.InteropServices;
    using System.Text;

    public class Mem
    {
        public int Add(Chain.Model.Mem model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("insert into Mem(");
            builder.Append("MemCard,MemPassword,MemName,MemSex,MemIdentityCard,MemMobile,MemPhoto,MemBirthdayType,MemBirthday,MemIsPast,MemPastTime,MemPoint,MemPointAutomatic,MemMoney,MemEmail,MemAddress,MemState,MemRecommendID,MemLevelID,MemShopID,MemCreateTime,MemRemark,MemUserID,MemTelePhone,MemQRCode,MemProvince,MemCity,MemCounty,MemVillage,MemQuestion,MemAnswer,MemWeiXinCard,MemCardNumber,MemAttention)");
            builder.Append(" values (");
            builder.Append("@MemCard,@MemPassword,@MemName,@MemSex,@MemIdentityCard,@MemMobile,@MemPhoto,@MemBirthdayType,@MemBirthday,@MemIsPast,@MemPastTime,@MemPoint,@MemPointAutomatic,@MemMoney,@MemEmail,@MemAddress,@MemState,@MemRecommendID,@MemLevelID,@MemShopID,@MemCreateTime,@MemRemark,@MemUserID,@MemTelePhone,@MemQRCode,@MemProvince,@MemCity,@MemCounty,@MemVillage,@MemQuestion,@MemAnswer,@MemWeiXinCard,@MemCardNumber,@MemAttention)");
            builder.Append(";select @@IDENTITY");
            SqlParameter[] cmdParms = new SqlParameter[] { 
                new SqlParameter("@MemCard", SqlDbType.VarChar, 50), new SqlParameter("@MemPassword", SqlDbType.NVarChar, 50), new SqlParameter("@MemName", SqlDbType.NVarChar, 50), new SqlParameter("@MemSex", SqlDbType.Bit, 1), new SqlParameter("@MemIdentityCard", SqlDbType.VarChar, 50), new SqlParameter("@MemMobile", SqlDbType.VarChar, 50), new SqlParameter("@MemPhoto", SqlDbType.NVarChar, 200), new SqlParameter("@MemBirthdayType", SqlDbType.Bit, 1), new SqlParameter("@MemBirthday", SqlDbType.DateTime), new SqlParameter("@MemIsPast", SqlDbType.Bit, 1), new SqlParameter("@MemPastTime", SqlDbType.DateTime), new SqlParameter("@MemPoint", SqlDbType.Int, 4), new SqlParameter("@MemPointAutomatic", SqlDbType.Bit, 1), new SqlParameter("@MemMoney", SqlDbType.Money, 8), new SqlParameter("@MemEmail", SqlDbType.VarChar, 50), new SqlParameter("@MemAddress", SqlDbType.NVarChar, 200), 
                new SqlParameter("@MemState", SqlDbType.Int, 1), new SqlParameter("@MemRecommendID", SqlDbType.Int, 4), new SqlParameter("@MemLevelID", SqlDbType.Int, 4), new SqlParameter("@MemShopID", SqlDbType.Int, 4), new SqlParameter("@MemCreateTime", SqlDbType.DateTime), new SqlParameter("@MemRemark", SqlDbType.NVarChar, 500), new SqlParameter("@MemUserID", SqlDbType.Int, 4), new SqlParameter("@MemTelePhone", SqlDbType.VarChar, 50), new SqlParameter("@MemQRCode", SqlDbType.VarChar, 500), new SqlParameter("@MemProvince", SqlDbType.VarChar, 50), new SqlParameter("@MemCity", SqlDbType.VarChar, 50), new SqlParameter("@MemCounty", SqlDbType.VarChar, 50), new SqlParameter("@MemVillage", SqlDbType.VarChar, 50), new SqlParameter("@MemQuestion", SqlDbType.VarChar, 500), new SqlParameter("@MemAnswer", SqlDbType.VarChar, 500), new SqlParameter("@MemWeiXinCard", SqlDbType.NVarChar, 50), 
                new SqlParameter("@MemCardNumber", SqlDbType.VarChar, 50), new SqlParameter("@MemAttention", SqlDbType.Int)
             };
            cmdParms[0].Value = model.MemCard;
            cmdParms[1].Value = model.MemPassword;
            cmdParms[2].Value = model.MemName;
            cmdParms[3].Value = model.MemSex;
            cmdParms[4].Value = model.MemIdentityCard;
            cmdParms[5].Value = model.MemMobile;
            cmdParms[6].Value = model.MemPhoto;
            cmdParms[7].Value = model.MemBirthdayType;
            cmdParms[8].Value = model.MemBirthday;
            cmdParms[9].Value = model.MemIsPast;
            cmdParms[10].Value = model.MemPastTime;
            cmdParms[11].Value = model.MemPoint;
            cmdParms[12].Value = model.MemPointAutomatic;
            cmdParms[13].Value = model.MemMoney;
            cmdParms[14].Value = model.MemEmail;
            cmdParms[15].Value = model.MemAddress;
            cmdParms[0x10].Value = model.MemState;
            cmdParms[0x11].Value = model.MemRecommendID;
            cmdParms[0x12].Value = model.MemLevelID;
            cmdParms[0x13].Value = model.MemShopID;
            cmdParms[20].Value = model.MemCreateTime;
            cmdParms[0x15].Value = model.MemRemark;
            cmdParms[0x16].Value = model.MemUserID;
            cmdParms[0x17].Value = model.MemTelePhone;
            cmdParms[0x18].Value = model.MemQRCode;
            cmdParms[0x19].Value = model.MemProvince;
            cmdParms[0x1a].Value = model.MemCity;
            cmdParms[0x1b].Value = model.MemCounty;
            cmdParms[0x1c].Value = model.MemVillage;
            cmdParms[0x1d].Value = model.MemQuestion;
            cmdParms[30].Value = model.MemAnswer;
            cmdParms[0x1f].Value = model.MemWeiXinCard;
            cmdParms[0x20].Value = model.MemCardNumber;
            cmdParms[0x21].Value = model.MemAttention;
            object single = DbHelperSQL.GetSingle(builder.ToString(), cmdParms);
            if (single == null)
            {
                return 0;
            }
            return Convert.ToInt32(single);
        }

        public int AddCustomField(string MemCard, Hashtable customhash)
        {
            DataSet list = new Chain.IDAL.MemCustomField().GetList(" CustomType=1");
            StringBuilder builder = new StringBuilder();
            if (list.Tables[0].Rows.Count > 0)
            {
                builder.Append(" update Mem set ");
                int num = 1;
                string str = "";
                foreach (DataRow row in list.Tables[0].Rows)
                {
                    if (customhash[row["CustomField"].ToString()] != null)
                    {
                        str = customhash[row["CustomField"].ToString()].ToString();
                    }
                    builder.AppendFormat(" {0}='{1}' ", row["CustomField"].ToString(), str);
                    if (num != list.Tables[0].Rows.Count)
                    {
                        builder.Append(",");
                    }
                    num++;
                }
                builder.AppendFormat(" where MemCard='{0}'", MemCard);
            }
            return DbHelperSQL.ExecuteSql(builder.ToString());
        }

        public int AddMemFirst(Chain.Model.Mem model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("insert into Mem(");
            builder.Append("MemCard,MemPassword,MemName,MemSex,MemIdentityCard,MemMobile,MemPhoto,MemBirthdayType,MemBirthday,MemIsPast,MemPastTime,MemPoint,MemPointAutomatic,MemMoney,MemEmail,MemAddress,MemState,MemRecommendID,MemLevelID,MemShopID,MemCreateTime,MemRemark,MemUserID,MemTelePhone,MemQRCode,MemProvince,MemCity,MemCounty,MemVillage,MemQuestion,MemAnswer,MemWeiXinCard,MemExpenseShop,MemCardNumber)");
            builder.Append(" values (");
            builder.Append("@MemCard,@MemPassword,@MemName,@MemSex,@MemIdentityCard,@MemMobile,@MemPhoto,@MemBirthdayType,@MemBirthday,@MemIsPast,@MemPastTime,@MemPoint,@MemPointAutomatic,@MemMoney,@MemEmail,@MemAddress,@MemState,@MemRecommendID,@MemLevelID,@MemShopID,@MemCreateTime,@MemRemark,@MemUserID,@MemTelePhone,@MemQRCode,@MemProvince,@MemCity,@MemCounty,@MemVillage,@MemQuestion,@MemAnswer,@MemWeiXinCard,@MemExpenseShop,@MemCardNumber)");
            builder.Append(";select @@IDENTITY");
            SqlParameter[] cmdParms = new SqlParameter[] { 
                new SqlParameter("@MemCard", SqlDbType.VarChar, 50), new SqlParameter("@MemPassword", SqlDbType.NVarChar, 50), new SqlParameter("@MemName", SqlDbType.NVarChar, 50), new SqlParameter("@MemSex", SqlDbType.Bit, 1), new SqlParameter("@MemIdentityCard", SqlDbType.VarChar, 50), new SqlParameter("@MemMobile", SqlDbType.VarChar, 50), new SqlParameter("@MemPhoto", SqlDbType.NVarChar, 200), new SqlParameter("@MemBirthdayType", SqlDbType.Bit, 1), new SqlParameter("@MemBirthday", SqlDbType.DateTime), new SqlParameter("@MemIsPast", SqlDbType.Bit, 1), new SqlParameter("@MemPastTime", SqlDbType.DateTime), new SqlParameter("@MemPoint", SqlDbType.Int, 4), new SqlParameter("@MemPointAutomatic", SqlDbType.Bit, 1), new SqlParameter("@MemMoney", SqlDbType.Money, 8), new SqlParameter("@MemEmail", SqlDbType.VarChar, 50), new SqlParameter("@MemAddress", SqlDbType.NVarChar, 200), 
                new SqlParameter("@MemState", SqlDbType.TinyInt, 1), new SqlParameter("@MemRecommendID", SqlDbType.Int, 4), new SqlParameter("@MemLevelID", SqlDbType.Int, 4), new SqlParameter("@MemShopID", SqlDbType.Int, 4), new SqlParameter("@MemCreateTime", SqlDbType.DateTime), new SqlParameter("@MemRemark", SqlDbType.NVarChar, 500), new SqlParameter("@MemUserID", SqlDbType.Int, 4), new SqlParameter("@MemTelePhone", SqlDbType.VarChar, 50), new SqlParameter("@MemQRCode", SqlDbType.VarChar, 500), new SqlParameter("@MemProvince", SqlDbType.VarChar, 50), new SqlParameter("@MemCity", SqlDbType.VarChar, 50), new SqlParameter("@MemCounty", SqlDbType.VarChar, 50), new SqlParameter("@MemVillage", SqlDbType.VarChar, 50), new SqlParameter("@MemQuestion", SqlDbType.VarChar, 500), new SqlParameter("@MemAnswer", SqlDbType.VarChar, 500), new SqlParameter("@MemWeiXinCard", SqlDbType.NVarChar, 50), 
                new SqlParameter("@MemExpenseShop", SqlDbType.NVarChar), new SqlParameter("@MemCardNumber", SqlDbType.NVarChar, 50)
             };
            cmdParms[0].Value = model.MemCard;
            cmdParms[1].Value = model.MemPassword;
            cmdParms[2].Value = model.MemName;
            cmdParms[3].Value = model.MemSex;
            cmdParms[4].Value = model.MemIdentityCard;
            cmdParms[5].Value = model.MemMobile;
            cmdParms[6].Value = model.MemPhoto;
            cmdParms[7].Value = model.MemBirthdayType;
            cmdParms[8].Value = model.MemBirthday;
            cmdParms[9].Value = model.MemIsPast;
            cmdParms[10].Value = model.MemPastTime;
            cmdParms[11].Value = model.MemPoint;
            cmdParms[12].Value = model.MemPointAutomatic;
            cmdParms[13].Value = model.MemMoney;
            cmdParms[14].Value = model.MemEmail;
            cmdParms[15].Value = model.MemAddress;
            cmdParms[0x10].Value = model.MemState;
            cmdParms[0x11].Value = model.MemRecommendID;
            cmdParms[0x12].Value = model.MemLevelID;
            cmdParms[0x13].Value = model.MemShopID;
            cmdParms[20].Value = model.MemCreateTime;
            cmdParms[0x15].Value = model.MemRemark;
            cmdParms[0x16].Value = model.MemUserID;
            cmdParms[0x17].Value = model.MemTelePhone;
            cmdParms[0x18].Value = model.MemQRCode;
            cmdParms[0x19].Value = model.MemProvince;
            cmdParms[0x1a].Value = model.MemCity;
            cmdParms[0x1b].Value = model.MemCounty;
            cmdParms[0x1c].Value = model.MemVillage;
            cmdParms[0x1d].Value = model.MemQuestion;
            cmdParms[30].Value = model.MemAnswer;
            cmdParms[0x1f].Value = model.MemWeiXinCard;
            cmdParms[0x20].Value = "";
            cmdParms[0x21].Value = model.MemCardNumber;
            object single = DbHelperSQL.GetSingle(builder.ToString(), cmdParms);
            if (single == null)
            {
                return 0;
            }
            return Convert.ToInt32(single);
        }

        public bool ChangeCard(Chain.Model.Mem modelMem, string newMemCard, string newPwd)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(" update mem set MemCard=@MemCard, ");
            builder.Append(" [MemPassword]=@MemPassword");
            builder.Append(" where MemID=@MemID ");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@MemCard", SqlDbType.VarChar, 50), new SqlParameter("@MemPassword", SqlDbType.VarChar, 50), new SqlParameter("@MemID", SqlDbType.Int, 4) };
            cmdParms[0].Value = newMemCard;
            cmdParms[1].Value = newPwd;
            cmdParms[2].Value = modelMem.MemID;
            return (DbHelperSQL.ExecuteSql(builder.ToString(), cmdParms) > 0);
        }

        public DataTable CheckMemPwd(string strAccount, string strPassword)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(" select  top 1 MemID,MemCard,MemPassword,MemName,MemSex,MemIdentityCard,MemMobile,MemPhoto,MemBirthdayType,MemBirthday,MemIsPast,MemPastTime,MemPoint,MemPointAutomatic,MemMoney,MemConsumeMoney,MemConsumeLastTime,MemConsumeCount,MemEmail,MemAddress,MemState,MemRecommendID,MemLevelID,MemShopID,MemCreateTime,MemRemark,MemUserID,MemTelePhone,MemQRCode,MemProvince,MemCity,MemCounty,MemVillage,MemQuestion,MemAnswer,MemWeiXinCard,MemCardNumber,MemWeiXinCards,MemAttention from Mem ");
            builder.Append(" where (MemCard =@MemCard or MemMobile=@MemCard or MemCardNumber=@MemCard) and MemPassword=@MemPassword ");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@MemCard", SqlDbType.VarChar, 50), new SqlParameter("@MemPassword", SqlDbType.VarChar, 200) };
            cmdParms[0].Value = strAccount;
            cmdParms[1].Value = strPassword;
            return DbHelperSQL.Query(builder.ToString(), cmdParms).Tables[0];
        }

        public bool ClearMemberPoint(int MemID)
        {
            DbHelperSQL.ExecuteSql(string.Format("update Mem  set MemPoint=0 where MemID={0}", MemID));
            return true;
        }

        public Chain.Model.Mem DataRowToModel(DataRow row)
        {
            Chain.Model.Mem mem = new Chain.Model.Mem();
            if (row != null)
            {
                if ((row["MemAttention"] != null) && (row["MemAttention"].ToString() != ""))
                {
                    mem.MemAttention = int.Parse(row["MemAttention"].ToString());
                }
                if ((row["MemWeiXinCards"] != null) && (row["MemWeiXinCards"].ToString() != ""))
                {
                    mem.MemWeiXinCards = row["MemWeiXinCards"].ToString();
                }
                if ((row["MemID"] != null) && (row["MemID"].ToString() != ""))
                {
                    mem.MemID = int.Parse(row["MemID"].ToString());
                }
                if (row["MemCard"] != null)
                {
                    mem.MemCard = row["MemCard"].ToString();
                }
                if (row["MemPassword"] != null)
                {
                    mem.MemPassword = row["MemPassword"].ToString();
                }
                if (row["MemName"] != null)
                {
                    mem.MemName = row["MemName"].ToString();
                }
                if ((row["MemSex"] != null) && (row["MemSex"].ToString() != ""))
                {
                    if ((row["MemSex"].ToString() == "1") || (row["MemSex"].ToString().ToLower() == "true"))
                    {
                        mem.MemSex = true;
                    }
                    else
                    {
                        mem.MemSex = false;
                    }
                }
                if (row["MemIdentityCard"] != null)
                {
                    mem.MemIdentityCard = row["MemIdentityCard"].ToString();
                }
                if (row["MemMobile"] != null)
                {
                    mem.MemMobile = row["MemMobile"].ToString();
                }
                if (row["MemPhoto"] != null)
                {
                    mem.MemPhoto = row["MemPhoto"].ToString();
                }
                if ((row["MemBirthdayType"] != null) && (row["MemBirthdayType"].ToString() != ""))
                {
                    if ((row["MemBirthdayType"].ToString() == "1") || (row["MemBirthdayType"].ToString().ToLower() == "true"))
                    {
                        mem.MemBirthdayType = true;
                    }
                    else
                    {
                        mem.MemBirthdayType = false;
                    }
                }
                if ((row["MemBirthday"] != null) && (row["MemBirthday"].ToString() != ""))
                {
                    mem.MemBirthday = DateTime.Parse(row["MemBirthday"].ToString());
                }
                if ((row["MemIsPast"] != null) && (row["MemIsPast"].ToString() != ""))
                {
                    if ((row["MemIsPast"].ToString() == "1") || (row["MemIsPast"].ToString().ToLower() == "true"))
                    {
                        mem.MemIsPast = true;
                    }
                    else
                    {
                        mem.MemIsPast = false;
                    }
                }
                if ((row["MemPastTime"] != null) && (row["MemPastTime"].ToString() != ""))
                {
                    mem.MemPastTime = DateTime.Parse(row["MemPastTime"].ToString());
                }
                if ((row["MemPoint"] != null) && (row["MemPoint"].ToString() != ""))
                {
                    mem.MemPoint = int.Parse(row["MemPoint"].ToString());
                }
                if ((row["MemPointAutomatic"] != null) && (row["MemPointAutomatic"].ToString() != ""))
                {
                    if ((row["MemPointAutomatic"].ToString() == "1") || (row["MemPointAutomatic"].ToString().ToLower() == "true"))
                    {
                        mem.MemPointAutomatic = true;
                    }
                    else
                    {
                        mem.MemPointAutomatic = false;
                    }
                }
                if ((row["MemMoney"] != null) && (row["MemMoney"].ToString() != ""))
                {
                    mem.MemMoney = decimal.Parse(row["MemMoney"].ToString());
                }
                if ((row["MemConsumeMoney"] != null) && (row["MemConsumeMoney"].ToString() != ""))
                {
                    mem.MemConsumeMoney = decimal.Parse(row["MemConsumeMoney"].ToString());
                }
                if ((row["MemConsumeLastTime"] != null) && (row["MemConsumeLastTime"].ToString() != ""))
                {
                    mem.MemConsumeLastTime = DateTime.Parse(row["MemConsumeLastTime"].ToString());
                }
                if ((row["MemConsumeCount"] != null) && (row["MemConsumeCount"].ToString() != ""))
                {
                    mem.MemConsumeCount = int.Parse(row["MemConsumeCount"].ToString());
                }
                if (row["MemEmail"] != null)
                {
                    mem.MemEmail = row["MemEmail"].ToString();
                }
                if (row["MemAddress"] != null)
                {
                    mem.MemAddress = row["MemAddress"].ToString();
                }
                if ((row["MemState"] != null) && (row["MemState"].ToString() != ""))
                {
                    mem.MemState = int.Parse(row["MemState"].ToString());
                }
                if ((row["MemRecommendID"] != null) && (row["MemRecommendID"].ToString() != ""))
                {
                    mem.MemRecommendID = int.Parse(row["MemRecommendID"].ToString());
                }
                if ((row["MemLevelID"] != null) && (row["MemLevelID"].ToString() != ""))
                {
                    mem.MemLevelID = int.Parse(row["MemLevelID"].ToString());
                }
                if ((row["MemShopID"] != null) && (row["MemShopID"].ToString() != ""))
                {
                    mem.MemShopID = int.Parse(row["MemShopID"].ToString());
                }
                if ((row["MemCreateTime"] != null) && (row["MemCreateTime"].ToString() != ""))
                {
                    mem.MemCreateTime = DateTime.Parse(row["MemCreateTime"].ToString());
                }
                if ((row["MemUserID"] != null) && (row["MemUserID"].ToString() != ""))
                {
                    mem.MemUserID = int.Parse(row["MemUserID"].ToString());
                }
                if (row["MemTelePhone"] != null)
                {
                    mem.MemTelePhone = row["MemTelePhone"].ToString();
                }
                if (row["MemRemark"] != null)
                {
                    mem.MemRemark = row["MemRemark"].ToString();
                }
                if (row["MemQRCode"] != null)
                {
                    mem.MemQRCode = row["MemQRCode"].ToString();
                }
                if ((row["MemProvince"] != null) && (row["MemProvince"].ToString() != ""))
                {
                    mem.MemProvince = row["MemProvince"].ToString();
                }
                if ((row["MemCity"] != null) && (row["MemCity"].ToString() != ""))
                {
                    mem.MemCity = row["MemCity"].ToString();
                }
                if ((row["MemCounty"] != null) && (row["MemCounty"].ToString() != ""))
                {
                    mem.MemCounty = row["MemCounty"].ToString();
                }
                if ((row["MemVillage"] != null) && (row["MemVillage"].ToString() != ""))
                {
                    mem.MemVillage = row["MemVillage"].ToString();
                }
                if ((row["MemQuestion"] != null) && (row["MemQuestion"].ToString() != ""))
                {
                    mem.MemQuestion = row["MemQuestion"].ToString();
                }
                if ((row["MemAnswer"] != null) && (row["MemAnswer"].ToString() != ""))
                {
                    mem.MemAnswer = row["MemAnswer"].ToString();
                }
                if ((row["MemWeiXinCard"] != null) && (row["MemWeiXinCard"].ToString() != ""))
                {
                    mem.MemWeiXinCard = row["MemWeiXinCard"].ToString();
                }
                if (row["MemCardNumber"] != null)
                {
                    mem.MemCardNumber = row["MemCardNumber"].ToString();
                }
            }
            return mem;
        }

        public bool Delete(int MemID)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("delete from Mem ");
            builder.Append(" where MemID=@MemID");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@MemID", SqlDbType.Int, 4) };
            cmdParms[0].Value = MemID;
            return (DbHelperSQL.ExecuteSql(builder.ToString(), cmdParms) > 0);
        }

        public bool DeleteList(string MemIDlist)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("delete from Mem ");
            builder.Append(" where MemID in (" + MemIDlist + ")  ");
            return (DbHelperSQL.ExecuteSql(builder.ToString()) > 0);
        }

        public int DrawMoney(int memID, decimal money)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(" update Mem set ");
            builder.Append(" MemMoney=MemMoney-@MemMoney");
            builder.Append(" where MemID=@MemID");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@MemMoney", SqlDbType.Money, 8), new SqlParameter("@MemID", SqlDbType.Int, 4) };
            cmdParms[0].Value = money;
            cmdParms[1].Value = memID;
            return DbHelperSQL.ExecuteSql(builder.ToString(), cmdParms);
        }

        public bool ExeclDataInput(ArrayList sqlArray)
        {
            return DbHelperSQL.ExecuteSqlTran(sqlArray);
        }

        public int ExistPwd(int MemID, string oldPwd)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat("select MemPassword from Mem where MemID={0}", MemID);
            if (DbHelperSQL.GetSingle(builder.ToString()).ToString() != oldPwd)
            {
                return -1;
            }
            return 1;
        }

        public bool Exists(int MemID)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select count(1) from Mem");
            builder.Append(" where MemID=@MemID");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@MemID", SqlDbType.Int, 4) };
            cmdParms[0].Value = MemID;
            return DbHelperSQL.Exists(builder.ToString(), cmdParms);
        }

        public int Exists(int MemID, string MemCard, string MemMobile, string MemCardNumber)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("DECLARE @MemID INT;");
            builder.Append("DECLARE @MemMobile NVARCHAR(50);");
            builder.Append("DECLARE @MemCardNumber NVARCHAR(50);");
            builder.Append("DECLARE @MemCard NVARCHAR(50);");
            builder.AppendFormat("SET @MemID='{0}';", MemID);
            builder.AppendFormat("SET @MemMobile='{0}';", MemMobile);
            builder.AppendFormat("SET @MemCardNumber='{0}';", MemCardNumber);
            builder.AppendFormat("SET @MemCard='{0}';", MemCard);
            StringBuilder builder2 = new StringBuilder();
            if (!string.IsNullOrEmpty(MemMobile))
            {
                builder2.AppendFormat("'{0}',", MemMobile);
            }
            if (!string.IsNullOrEmpty(MemCardNumber))
            {
                builder2.AppendFormat("'{0}',", MemCardNumber);
            }
            if (!string.IsNullOrEmpty(MemCard))
            {
                builder2.AppendFormat("'{0}',", MemCard);
            }
            string str = "";
            if (builder2.Length > 0)
            {
                str = builder2.ToString().Trim(new char[] { ',' });
            }
            if (MemID > 0)
            {
                builder.AppendFormat(" IF EXISTS(SELECT 1 FROM dbo.Mem WHERE MemCard IN ({0}) AND MemID<>@MemID ) ", str);
                builder.Append(" BEGIN ");
                builder.Append("     SELECT -1 ");
                builder.Append(" END ");
                builder.AppendFormat(" ELSE IF EXISTS(SELECT 1 FROM dbo.Mem WHERE  MemMobile IN ({0}) AND MemID<>@MemID ) ", str);
                builder.Append(" BEGIN ");
                builder.Append("     SELECT -2 ");
                builder.Append(" END ");
                builder.AppendFormat(" ELSE IF EXISTS(SELECT 1 FROM dbo.Mem WHERE MemCardNumber IN ({0}) AND MemID<>@MemID ) ", str);
                builder.Append(" BEGIN ");
                builder.Append("     SELECT -6 ");
                builder.Append(" END ");
            }
            else
            {
                builder.AppendFormat(" IF EXISTS(SELECT 1 FROM dbo.Mem WHERE MemCard IN ({0})) ", str);
                builder.Append(" BEGIN ");
                builder.Append("     SELECT -1 ");
                builder.Append(" END ");
                builder.AppendFormat(" ELSE IF EXISTS(SELECT 1 FROM dbo.Mem WHERE  MemMobile IN ({0})) ", str);
                builder.Append(" BEGIN ");
                builder.Append("     SELECT -2 ");
                builder.Append(" END ");
                builder.AppendFormat(" ELSE IF EXISTS(SELECT 1 FROM dbo.Mem WHERE MemCardNumber IN ({0})) ", str);
                builder.Append(" BEGIN ");
                builder.Append("     SELECT -6 ");
                builder.Append(" END ");
            }
            DataSet set = DbHelperSQL.Query(builder.ToString());
            DataTable table = (set.Tables.Count > 0) ? set.Tables[0] : new DataTable();
            if (table.Rows.Count > 0)
            {
                return (int) table.Rows[0][0];
            }
            return 1;
        }

        public bool ExistsMemCard(string MemCard)
        {
            return DbHelperSQL.Exists(string.Format("select count(1) from Mem where MemCard = '{0}'", MemCard).ToString());
        }

        public int ExpenseUpdateMem(int memID, decimal dclMemMoney, decimal memConsumeMoney, int point, DateTime dtime, int count)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("update Mem set ");
            builder.Append("MemMoney=@MemMoney,");
            builder.Append("MemConsumeMoney=@MemConsumeMoney,");
            builder.Append("MemPoint=@MemPoint,");
            builder.Append("MemConsumeLastTime=@MemConsumeLastTime,");
            builder.Append("MemConsumeCount=@MemConsumeCount");
            builder.Append(" where MemID=@MemID");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@MemMoney", SqlDbType.Money, 8), new SqlParameter("@MemConsumeMoney", SqlDbType.Money, 8), new SqlParameter("@MemPoint", SqlDbType.Int, 4), new SqlParameter("@MemConsumeLastTime", SqlDbType.DateTime), new SqlParameter("@MemConsumeCount", SqlDbType.Int, 4), new SqlParameter("@MemID", SqlDbType.Int, 4) };
            cmdParms[0].Value = dclMemMoney;
            cmdParms[1].Value = memConsumeMoney;
            cmdParms[2].Value = point;
            cmdParms[3].Value = dtime;
            cmdParms[4].Value = count;
            cmdParms[5].Value = memID;
            int num = DbHelperSQL.ExecuteSql(builder.ToString(), cmdParms);
            if (num > 0)
            {
                return num;
            }
            return 0;
        }

        public DataSet GetBirthdayList(int day, int shopID)
        {
            StringBuilder builder = new StringBuilder();
            if (day > 0)
            {
                builder.AppendFormat("select Mem.*,(select ShopName from SysShop where Mem.MemShopID = SysShop.ShopID) as ShopName,(select LevelName from MemLevel where Mem.MemLevelID = MemLevel.LevelID) as LevelName from Mem where DATEDIFF(DAY,GETDATE(),DATEADD(YEAR,DATEDIFF(YEAR,MemBirthday,GETDATE()),MemBirthday)) BETWEEN 1 AND {0}", day);
            }
            else if (day == 0)
            {
                builder.Append("select Mem.*,(select ShopName from SysShop where Mem.MemShopID = SysShop.ShopID) as ShopName,(select LevelName from MemLevel where Mem.MemLevelID = MemLevel.LevelID) as LevelName from Mem where DATEDIFF(DAY,GETDATE(),DATEADD(YEAR,DATEDIFF(YEAR,MemBirthday,GETDATE()),MemBirthday))=0");
            }
            if (shopID != 1)
            {
                builder.AppendFormat(" and MemShopID={0}", shopID);
            }
            return DbHelperSQL.Query(builder.ToString());
        }

        public DataSet GetBirthdayList(int day, int shopID, int count)
        {
            StringBuilder builder = new StringBuilder();
            if (day > 0)
            {
                builder.AppendFormat("select top " + count + " Mem.*,(select ShopName from SysShop where Mem.MemShopID = SysShop.ShopID) as ShopName,(select LevelName from MemLevel where Mem.MemLevelID = MemLevel.LevelID) as LevelName from Mem where month(MemBirthday)=month(getdate()) and (day(MemBirthday)-day(getdate()))>0 and (day(MemBirthday)-day(getdate()))<={0}", day);
            }
            else if (day == 0)
            {
                builder.AppendFormat("select top " + count + " Mem.*,(select ShopName from SysShop where Mem.MemShopID = SysShop.ShopID) as ShopName,(select LevelName from MemLevel where Mem.MemLevelID = MemLevel.LevelID) as LevelName from Mem where month(MemBirthday)=month(getdate()) and day(MemBirthday)-day(getdate())={0}", day);
            }
            if (shopID != 1)
            {
                builder.AppendFormat(" and MemShopID={0}", shopID);
            }
            return DbHelperSQL.Query(builder.ToString());
        }

        public DataSet GetDataByTime(DateTime starttime, DateTime endtime, string strwhere)
        {
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@StartTime", SqlDbType.DateTime), new SqlParameter("@EndTime", SqlDbType.DateTime), new SqlParameter("@strWhere", SqlDbType.NVarChar, 0x7d0) };
            parameters[0].Value = starttime;
            parameters[1].Value = endtime;
            parameters[2].Value = strwhere;
            return DbHelperSQL.RunProcedure("MonthData", parameters, "#MyData");
        }

        public DataSet GetItemAll(int MemID)
        {
            return DbHelperSQL.Query(" select * from Mem where MemID =" + MemID);
        }

        public DataSet GetList(string strWhere)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select *");
            builder.Append(" FROM Mem ");
            if (strWhere.Trim() != "")
            {
                builder.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(builder.ToString());
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select ");
            if (Top > 0)
            {
                builder.Append(" top " + Top.ToString());
            }
            builder.Append(" * ");
            builder.Append(" FROM Mem ");
            if (strWhere.Trim() != "")
            {
                builder.Append(" where " + strWhere);
            }
            builder.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(builder.ToString());
        }

        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("SELECT * FROM ( ");
            builder.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                builder.Append("order by T." + orderby);
            }
            else
            {
                builder.Append("order by T.MemID desc");
            }
            builder.Append(")AS Row, T.*  from Mem T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                builder.Append(" WHERE " + strWhere);
            }
            builder.Append(" ) TT");
            builder.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(builder.ToString());
        }

        public DataSet GetListS(int PageSize, int PageIndex, string[] strWhere, out int resCount)
        {
            string tableName = "Mem";
            string[] column = new string[] { "*" };
            string[] condition = strWhere;
            int recordCount = 1;
            DataSet set = DbHelperSQL.GetTable(tableName, column, condition, "MemID", true, PageSize, PageIndex, recordCount);
            resCount = int.Parse(set.Tables[1].Rows[0][0].ToString());
            return set;
        }

        public DataSet GetListSP(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            string tableName = "Mem,SysShop,MemLevel,SysUser,SysShopMemLevel";
            string[] column = new string[] { "Mem.*,SysShop.ShopName,MemLevel.*,ClassDiscountPercent,ClassPointPercent,isnull(Mem.MemConsumeMoney,0) as ConsumeMoney, SysUser.UserName,(select Name from SysArea where Mem.MemProvince=SysArea.ID) as MemProvinceName,(select Name from SysArea where Mem.MemCity=SysArea.ID) as MemCityName,(select Name from SysArea where Mem.MemCounty=SysArea.ID) as MemCountyName,(select Name from SysArea where Mem.MemVillage=SysArea.ID) as MemVillageName,isnull((select sum(CountDetailNumber) from MemCountDetail where CountDetailMemID=Mem.MemID),0) as MemCountNumber,SysShopMemLevel.ClassRechargePointRate ", "(SELECT COUNT(1) FROM dbo.Mem ca WHERE ca.MemRecommendID=dbo.Mem.MemID AND ca.MemRecommendID>0 ) AS RecommendCount,ISNULL((SELECT SUM(ISNULL(PointNumber,0)) FROM dbo.PointLog cp WHERE EXISTS(SELECT 1 FROM dbo.Mem caa WHERE caa.MemRecommendID=dbo.Mem.MemID AND cp.PointGiveMemID=caa.MemID)),0) AS RecommendPoint" };
            string[] condition = strWhere;
            int recordCount = 1;
            DataSet set = DbHelperSQL.GetTable(tableName, column, condition, "MemID", "MemID", false, PageSize, PageIndex, recordCount);
            resCount = int.Parse(set.Tables[1].Rows[0][0].ToString());
            return set;
        }

        public int GetMaxId()
        {
            return DbHelperSQL.GetMaxID("MemID", "Mem");
        }

        public DataTable GetMemAdressBymencard(string MemCard)
        {
            StringBuilder builder = new StringBuilder();
            string str = string.Format("select (select Name from SysArea where Mem.MemProvince=SysArea.ID) as MemProvinceName,(select Name from SysArea where Mem.MemCity=SysArea.ID) as MemCityName,(select Name from SysArea where Mem.MemCounty=SysArea.ID) as MemCountyName,(select Name from SysArea where Mem.MemVillage=SysArea.ID) as MemVillageName,MemAddress from  Mem where MemCard='{0}'", MemCard);
            builder.Append(str);
            DataSet set = DbHelperSQL.Query(builder.ToString());
            if (set.Tables[0].Rows.Count > 0)
            {
                return set.Tables[0];
            }
            return null;
        }

        public DataSet GetMemBirthday(int day)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select * from Mem where  ");
            builder.Append("datepart(year,MemBirthday)!='1900' ");
            builder.Append("and datepart(month,getdate())=datepart(month,MemBirthday-@day) ");
            builder.Append("and datepart(day,MemBirthday-@day)=datepart(day,getdate()) ");
            builder.Append("and MemMobile!='' ");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@day", SqlDbType.Int, 4) };
            cmdParms[0].Value = day;
            return DbHelperSQL.Query(builder.ToString(), cmdParms);
        }

        public Chain.Model.Mem GetMemByWeiXinCard(string weiXinCard)
        {
            string sQLString = "select * from Mem where MemWeiXinCard=@MemWeiXinCard";
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@MemWeiXinCard", SqlDbType.NVarChar, 50) };
            cmdParms[0].Value = weiXinCard;
            new Chain.Model.Mem();
            DataTable table = DbHelperSQL.Query(sQLString, cmdParms).Tables[0];
            if (table.Rows.Count > 0)
            {
                return this.DataRowToModel(table.Rows[0]);
            }
            return null;
        }

        public DataSet GetMemConsumeMoney(string strWhere)
        {
            return DbHelperSQL.Query(string.Format(" select sum(MemConsumeMoney)as MemConsumeMoney from Mem where {0}", strWhere));
        }

        public int GetMemCount(string strWhere)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(" select count(MemID) from Mem");
            if (strWhere.Trim() != "")
            {
                builder.Append(" where " + strWhere);
            }
            object single = DbHelperSQL.GetSingle(builder.ToString());
            if (single != null)
            {
                return Convert.ToInt32(single);
            }
            return 0;
        }

        public DataSet GetMemExpense(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            string tableName = "V_RptMemExpense";
            string[] column = new string[] { "*" };
            string[] condition = strWhere;
            int recordCount = 1;
            DataSet set = DbHelperSQL.GetTable(tableName, column, condition, "MemConsumeLastTime", "MemCard", false, PageSize, PageIndex, recordCount);
            resCount = int.Parse(set.Tables[1].Rows[0][0].ToString());
            return set;
        }

        public DataSet GetMemExpense(int PageSize, int PageIndex, out int resCount, string strTime, params string[] strWhere)
        {
            string[] strArray;
            string tableName = "Mem,SysShop";
            //strArray = new string[] { strArray[0].Replace("1=1", strTime) };
            strArray = new string[] { ("1=1") };
            string[] condition = strWhere;
            int recordCount = 1;
            DataSet set = DbHelperSQL.GetTable(tableName, strArray, condition, "MemID", false, PageSize, PageIndex, recordCount);
            resCount = int.Parse(set.Tables[1].Rows[0][0].ToString());
            return set;
        }

        public DataSet GetMemExpenseDetail(string strWhere)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(" select * from V_RptMemExpense");
            if (strWhere.Trim() != "")
            {
                builder.Append(" where " + strWhere);
            }
            builder.Append(" Order by OrderCreateTime desc");
            return DbHelperSQL.Query(builder.ToString());
        }

        public DataSet GetMemExpenseToWeiXin(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            string tableName = "V_RptMemExpense";
            string[] column = new string[] { "*" };
            string[] condition = strWhere;
            int recordCount = 1;
            DataSet set = DbHelperSQL.GetTable(tableName, column, condition, "OrderCreateTime", false, PageSize, PageIndex, recordCount);
            resCount = int.Parse(set.Tables[1].Rows[0][0].ToString());
            return set;
        }

        public Chain.Model.Mem GetMemInfoByMobile(string Mobile)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(" select top 1 *");
            builder.Append(" from Mem");
            builder.Append(" where MemMobile=@MemMobile");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@MemMobile", SqlDbType.VarChar, 50) };
            cmdParms[0].Value = Mobile;
            new Chain.Model.Mem();
            DataSet set = DbHelperSQL.Query(builder.ToString(), cmdParms);
            if (set.Tables[0].Rows.Count > 0)
            {
                return this.DataRowToModel(set.Tables[0].Rows[0]);
            }
            return null;
        }

        public DataSet GetMemPast(int day)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select * from Mem where  ");
            builder.Append("datepart(year,MemPastTime-@day)=datepart(year,getdate()) ");
            builder.Append("and datepart(month,getdate())=datepart(month,MemPastTime-@day) ");
            builder.Append("and datepart(day,MemPastTime-@day)=datepart(day,getdate()) ");
            builder.Append("and MemMobile!='' ");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@day", SqlDbType.Int, 4) };
            cmdParms[0].Value = day;
            return DbHelperSQL.Query(builder.ToString(), cmdParms);
        }

        public DataSet GetMemPastTime(string strSql, int shopID)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select mem.*,SysShop.ShopName,MemLevel.LevelName from mem inner join SysShop on mem.MemShopID = SysShop.ShopID inner join MemLevel on Mem.MemLevelID = MemLevel.LevelID where MemID<>0 and MemPastTime <> '2900-01-01'");
            builder.Append(strSql);
            if (shopID != 1)
            {
                builder.AppendFormat(" and MemShopID={0}", shopID);
            }
            return DbHelperSQL.Query(builder.ToString());
        }

        public DataSet GetMemPastTime(string strSql, int shopID, int count)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select top " + count + " mem.*,SysShop.ShopName,MemLevel.LevelName from mem inner join SysShop on mem.MemShopID = SysShop.ShopID inner join MemLevel on Mem.MemLevelID = MemLevel.LevelID where MemID<>0 and MemPastTime <> '2900-01-01'");
            builder.Append(strSql);
            if (shopID != 1)
            {
                builder.AppendFormat(" and MemShopID={0}", shopID);
            }
            return DbHelperSQL.Query(builder.ToString());
        }

        public DataTable getMemPayList(int PageSize, int PageIndex, string[] strWhere, out int resCount)
        {
            string tableName = "V_MemPay INNER JOIN dbo.Mem ON V_MemPay.MemID=dbo.Mem.MemID INNER JOIN dbo.SysUser ON MemUserID=UserID INNER JOIN dbo.SysShop ON MemShopID=ShopID";
            string[] column = new string[] { "V_MemPay.*,MemCard,MemName,MemMobile,MemCreateTime,UserName,MemMoney,MemPoint,MemConsumeMoney,ShopName,MemState" };
            string[] condition = strWhere;
            int recordCount = 1;
            using (DataSet set = DbHelperSQL.GetTable(tableName, column, condition, "Mem.MemID", true, PageSize, PageIndex, recordCount))
            {
                resCount = int.Parse(set.Tables[1].Rows[0][0].ToString());
                return set.Tables[0];
            }
        }

        public DataSet GetMemPointReset(string strSql, int type)
        {
            StringBuilder builder = new StringBuilder();
            if (type == 0)
            {
                builder.Append(" select MemID,MemCard,MemName,MemPoint,MemMobile,MemPastTime,MemConsumeLastTime,MemConsumeCount,DATEDIFF(day,MemConsumeLastTime,getdate()) as CountingDown,");
            }
            else
            {
                builder.Append(" select MemID,MemCard,MemName,MemPoint,MemMobile,MemPastTime,MemConsumeLastTime,MemConsumeCount,DATEDIFF(day,MemConsumeLastTime,getdate()) as CountingDown,");
            }
            builder.Append(" (select ShopName from SysShop where Mem.MemShopID = SysShop.ShopID) as ShopName,(select LevelName from MemLevel where Mem.MemLevelID = MemLevel.LevelID) as LevelName");
            builder.Append(" from Mem where MemID<>0");
            if (strSql.ToString() != "")
            {
                builder.Append(" and " + strSql);
            }
            return DbHelperSQL.Query(builder.ToString());
        }

        public DataSet GetMemPointReset(string strSql, int type, int count)
        {
            StringBuilder builder = new StringBuilder();
            if (type == 0)
            {
                builder.Append(" select top " + count + " MemID,MemCard,MemName,MemPoint,MemMobile,MemPastTime,MemConsumeLastTime,MemConsumeCount,DATEDIFF(day,MemConsumeLastTime,getdate()) as CountingDown,");
            }
            else
            {
                builder.Append(" select top " + count + " MemID,MemCard,MemName,MemPoint,MemMobile,MemPastTime,MemConsumeLastTime,MemConsumeCount,DATEDIFF(day,MemConsumeLastTime,getdate()) as CountingDown,");
            }
            builder.Append(" (select ShopName from SysShop where Mem.MemShopID = SysShop.ShopID) as ShopName,(select LevelName from MemLevel where Mem.MemLevelID = MemLevel.LevelID) as LevelName");
            builder.Append(" from Mem where MemID<>0");
            if (strSql.ToString() != "")
            {
                builder.Append(" and " + strSql);
            }
            return DbHelperSQL.Query(builder.ToString());
        }

        public DataTable getMemRecommend(object memid)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat("SELECT ROW_NUMBER() OVER(ORDER BY MemID) AS Rowid ,ISNULL((SELECT SUM(ISNULL(PointNumber,0)) FROM dbo.PointLog WHERE PointMemID='{0}' AND PointGiveMemID=dbo.Mem.MemID),0) AS SumNumber,MemCard,MemName,MemMobile FROM dbo.Mem WHERE MemRecommendID='{0}' ORDER BY MemID ASC", memid);
            using (DataTable table = DbHelperSQL.Query(builder.ToString()).Tables[0])
            {
                return table;
            }
        }

        public DataTable GetMemRecommendList(int memid)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat("SELECT MemID, MemCard,MemName,MemMobile FROM dbo.Mem WHERE MemRecommendID='{0}' ORDER BY MemID ASC", memid);
            using (DataTable table = DbHelperSQL.Query(builder.ToString()).Tables[0])
            {
                return table;
            }
        }

        public Chain.Model.Mem GetMemWeiXinCardModel(string strMemWeiXinCard, string strAttributes)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(" select top 1 *");
            builder.Append(" from Mem");
            builder.AppendFormat(" where {0}=@{0}", strAttributes);
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter(string.Format("@{0}", strAttributes), SqlDbType.VarChar, 50) };
            cmdParms[0].Value = strMemWeiXinCard;
            new Chain.Model.Mem();
            DataSet set = DbHelperSQL.Query(builder.ToString(), cmdParms);
            if (set.Tables[0].Rows.Count > 0)
            {
                return this.DataRowToModel(set.Tables[0].Rows[0]);
            }
            return null;
        }

        public Chain.Model.Mem GetModel(int MemID)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(" select top 1 *");
            builder.Append(" from Mem");
            builder.Append(" where MemID=@MemID");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@MemID", SqlDbType.Int, 4) };
            cmdParms[0].Value = MemID;
            new Chain.Model.Mem();
            DataSet set = DbHelperSQL.Query(builder.ToString(), cmdParms);
            if (set.Tables[0].Rows.Count > 0)
            {
                return this.DataRowToModel(set.Tables[0].Rows[0]);
            }
            return null;
        }

        public Chain.Model.Mem GetModel(string memCard)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(" select top 1 *");
            builder.Append(" from Mem");
            builder.Append(" where MemCard=@MemCard");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@MemCard", SqlDbType.VarChar, 50) };
            cmdParms[0].Value = memCard;
            new Chain.Model.Mem();
            DataSet set = DbHelperSQL.Query(builder.ToString(), cmdParms);
            if (set.Tables[0].Rows.Count > 0)
            {
                return this.DataRowToModel(set.Tables[0].Rows[0]);
            }
            return null;
        }

        public Chain.Model.Mem GetModelByMemCard(string MemCard)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(" select top 1 *");
            builder.Append(" from Mem");
            builder.Append(" where MemCard=@MemCard");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@MemCard", SqlDbType.VarChar, 50) };
            cmdParms[0].Value = MemCard;
            new Chain.Model.Mem();
            DataSet set = DbHelperSQL.Query(builder.ToString(), cmdParms);
            if (set.Tables[0].Rows.Count > 0)
            {
                return this.DataRowToModel(set.Tables[0].Rows[0]);
            }
            return null;
        }

        public Chain.Model.Mem GetModelByMemMobile(string MemMobile)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(" select top 1 *");
            builder.Append(" from Mem");
            builder.Append(" where MemMobile=@MemMobile");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@MemMobile", SqlDbType.VarChar, 50) };
            cmdParms[0].Value = MemMobile;
            new Chain.Model.Mem();
            DataSet set = DbHelperSQL.Query(builder.ToString(), cmdParms);
            if (set.Tables[0].Rows.Count > 0)
            {
                return this.DataRowToModel(set.Tables[0].Rows[0]);
            }
            return null;
        }

        public DataTable GetModelDetail(params string[] strWhere)
        {
            string tableName = "Mem,SysShop,MemLevel,SysUser,SysShopMemLevel";
            string[] column = new string[] { "Mem.*,SysShop.ShopName,MemLevel.*,ClassDiscountPercent,ClassPointPercent,isnull(Mem.MemConsumeMoney,0) as ConsumeMoney, SysUser.UserName,(select Name from SysArea where Mem.MemProvince=SysArea.ID) as MemProvinceName,(select Name from SysArea where Mem.MemCity=SysArea.ID) as MemCityName,(select Name from SysArea where Mem.MemCounty=SysArea.ID) as MemCountyName,(select Name from SysArea where Mem.MemVillage=SysArea.ID) as MemVillageName,isnull((select sum(CountDetailNumber) from MemCountDetail where CountDetailMemID=Mem.MemID),0) as MemCountNumber,SysShopMemLevel.ClassRechargePointRate " };
            string[] condition = strWhere;
            int recordCount = 1;
            //return DbHelperSQL.GetTable(tableName, column, condition, "MemID", "MemID", 0, 1, 1, recordCount).Tables[0];
            return DbHelperSQL.GetTable(tableName, column, condition, "MemID", "MemID", false, 1, 1, recordCount).Tables[0];
        }

        public DataSet GetPointRankList(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            string tableName = "Mem,SysShop,MemLevel";
            string[] column = new string[] { "Mem.*,SysShop.ShopName,MemLevel.*" };
            string[] condition = strWhere;
            int recordCount = 1;
            DataSet set = DbHelperSQL.GetTable(tableName, column, condition, "MemPoint", false, PageSize, PageIndex, recordCount);
            resCount = int.Parse(set.Tables[1].Rows[0][0].ToString());
            return set;
        }

        public int GetRecordCount(string strWhere)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select count(1) FROM Mem ");
            if (strWhere.Trim() != "")
            {
                builder.Append(" where " + strWhere);
            }
            object single = DbHelperSQL.GetSingle(builder.ToString());
            if (single == null)
            {
                return 0;
            }
            return Convert.ToInt32(single);
        }

        public DataSet IsCanDelMem(int MemID)
        {
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@MemID", SqlDbType.Int) };
            parameters[0].Value = MemID;
            return DbHelperSQL.RunProcedure("MemIsCanDel", parameters, "#MemIsCanDel");
        }

        public int MemCountUpdateMem(int memID, decimal dclMemMoney, int point)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("update Mem set ");
            builder.Append("MemMoney=@MemMoney,");
            builder.Append("MemPoint=@MemPoint");
            builder.Append(" where MemID=@MemID");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@MemMoney", SqlDbType.Money, 8), new SqlParameter("@MemPoint", SqlDbType.Int, 4), new SqlParameter("@MemID", SqlDbType.Int, 4) };
            cmdParms[0].Value = dclMemMoney;
            cmdParms[1].Value = point;
            cmdParms[2].Value = memID;
            int num = DbHelperSQL.ExecuteSql(builder.ToString(), cmdParms);
            if (num > 0)
            {
                return num;
            }
            return 0;
        }

        public int MemRegister(string CardID, string LevelID, int userid, int shopid, string phone, string name)
        {
            return DbHelperSQL.ExecuteSql(string.Concat(new object[] { "INSERT [Mem] ([MemCard] , [MemPassword] , [MemName] , [MemSex] , [MemIdentityCard] , [MemMobile] , [MemPhoto] , [MemBirthdayType] , [MemBirthday] , [MemIsPast] , [MemPastTime] , [MemPoint] , [MemPointAutomatic] , [MemMoney] , [MemEmail] , [MemAddress] , [MemState] , [MemRecommendID] , [MemLevelID] , [MemShopID] , [MemCreateTime] , [MemRemark] , [MemUserID] , [MemTelePhone] , [MemQRCode] , [MemProvince] , [MemCity] , [MemCounty] , [MemVillage] , [MemCardNumber] ) VALUES ('", CardID, "' , 'E62A9E6C1892C6BB' , '", name, "' , 1 , '' , '", phone, "' , '' , 1 , '1900-01-01 00:00:00.000' , 0 , '2900-01-01 00:00:00.000' , 0 , 1 , .0000 , '' , '' , 0 , 0 , ", LevelID, " , ", shopid, " , GETDATE() , '' , ", userid, " , '' , '' , '' , '' , '' , '' , '' )" }));
        }

        public int SecuritySettings(int intMemID, string strEmail, string strQuestion, string strAnswer)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(" Update Mem set");
            builder.Append(" MemEmail=@MemEmail,");
            builder.Append(" MemQuestion=@MemQuestion,");
            builder.Append(" MemAnswer=@MemAnswer");
            builder.Append(" where MemID=@MemID");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@MemEmail", SqlDbType.VarChar, 50), new SqlParameter("@MemQuestion", SqlDbType.VarChar, 500), new SqlParameter("@MemAnswer", SqlDbType.VarChar, 500), new SqlParameter("@MemID", SqlDbType.Int, 4) };
            cmdParms[0].Value = strEmail;
            cmdParms[1].Value = strQuestion;
            cmdParms[2].Value = strAnswer;
            cmdParms[3].Value = intMemID;
            object obj2 = DbHelperSQL.ExecuteSql(builder.ToString(), cmdParms);
            if (obj2 == null)
            {
                return 0;
            }
            return Convert.ToInt32(obj2);
        }

        public int SysUpdateMemIsPast()
        {
            string sQLString = " update Mem set MemIsPast = 1 where getdate()>= MemPastTime ";
            return DbHelperSQL.ExecuteSql(sQLString);
        }

        public int Update(Chain.Model.Mem model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("update Mem set ");
            builder.Append("MemCard=@MemCard,");
            builder.Append("MemName=@MemName,");
            builder.Append("MemSex=@MemSex,");
            builder.Append("MemIdentityCard=@MemIdentityCard,");
            builder.Append("MemMobile=@MemMobile,");
            builder.Append("MemPhoto=@MemPhoto,");
            builder.Append("MemBirthday=@MemBirthday,");
            builder.Append("MemIsPast=@MemIsPast,");
            builder.Append("MemPastTime=@MemPastTime,");
            builder.Append("MemPoint=@MemPoint,");
            builder.Append("MemMoney=@MemMoney,");
            builder.Append("MemEmail=@MemEmail,");
            builder.Append("MemAddress=@MemAddress,");
            builder.Append("MemState=@MemState,");
            builder.Append("MemRecommendID=@MemRecommendID,");
            builder.Append("MemLevelID=@MemLevelID,");
            builder.Append("MemShopID=@MemShopID,");
            builder.Append("MemCreateTime=@MemCreateTime,");
            builder.Append("MemRemark=@MemRemark,");
            builder.Append("MemConsumeMoney=@MemConsumeMoney,");
            builder.Append("MemUserID=@MemUserID,");
            builder.Append("MemTelePhone=@MemTelePhone,");
            builder.Append("MemProvince=@MemProvince,");
            builder.Append("MemCity=@MemCity,");
            builder.Append("MemCounty=@MemCounty,");
            builder.Append("MemVillage=@MemVillage,");
            builder.Append("MemQuestion=@MemQuestion,");
            builder.Append("MemAnswer=@MemAnswer,");
            builder.Append("MemWeiXinCard=@MemWeiXinCard,");
            builder.Append("MemCardNumber=@MemCardNumber,");
            builder.Append("MemWeiXinCards=@MemWeiXinCards,");
            builder.Append("MemAttention=@MemAttention");
            builder.Append(" where MemID=@MemID");
            SqlParameter[] cmdParms = new SqlParameter[] { 
                new SqlParameter("@MemCard", SqlDbType.VarChar, 50), new SqlParameter("@MemName", SqlDbType.NVarChar, 50), new SqlParameter("@MemSex", SqlDbType.Bit, 1), new SqlParameter("@MemIdentityCard", SqlDbType.VarChar, 50), new SqlParameter("@MemMobile", SqlDbType.VarChar, 50), new SqlParameter("@MemPhoto", SqlDbType.NVarChar, 200), new SqlParameter("@MemBirthday", SqlDbType.DateTime), new SqlParameter("@MemIsPast", SqlDbType.Bit, 1), new SqlParameter("@MemPastTime", SqlDbType.DateTime), new SqlParameter("@MemPoint", SqlDbType.Int, 4), new SqlParameter("@MemMoney", SqlDbType.Money, 8), new SqlParameter("@MemEmail", SqlDbType.VarChar, 50), new SqlParameter("@MemAddress", SqlDbType.NVarChar, 200), new SqlParameter("@MemState", SqlDbType.TinyInt, 1), new SqlParameter("@MemRecommendID", SqlDbType.Int, 4), new SqlParameter("@MemLevelID", SqlDbType.Int, 4), 
                new SqlParameter("@MemShopID", SqlDbType.Int, 4), new SqlParameter("@MemCreateTime", SqlDbType.DateTime), new SqlParameter("@MemRemark", SqlDbType.NVarChar, 500), new SqlParameter("@MemConsumeMoney", SqlDbType.Money, 8), new SqlParameter("@MemUserID", SqlDbType.Int, 4), new SqlParameter("@MemTelePhone", SqlDbType.VarChar, 50), new SqlParameter("@MemProvince", SqlDbType.VarChar, 50), new SqlParameter("@MemCity", SqlDbType.VarChar, 50), new SqlParameter("@MemCounty", SqlDbType.VarChar, 50), new SqlParameter("@MemVillage", SqlDbType.VarChar, 50), new SqlParameter("@MemQuestion", SqlDbType.VarChar, 500), new SqlParameter("@MemAnswer", SqlDbType.VarChar, 500), new SqlParameter("@MemWeiXinCard", SqlDbType.NVarChar, 50), new SqlParameter("@MemCardNumber", SqlDbType.VarChar, 50), new SqlParameter("@MemWeiXinCards", SqlDbType.NVarChar, 50), new SqlParameter("@MemAttention", SqlDbType.Int), 
                new SqlParameter("@MemID", SqlDbType.Int, 4)
             };
            cmdParms[0].Value = model.MemCard;
            cmdParms[1].Value = model.MemName;
            cmdParms[2].Value = model.MemSex;
            cmdParms[3].Value = model.MemIdentityCard;
            cmdParms[4].Value = model.MemMobile;
            cmdParms[5].Value = model.MemPhoto;
            cmdParms[6].Value = model.MemBirthday;
            cmdParms[7].Value = model.MemIsPast;
            cmdParms[8].Value = model.MemPastTime;
            cmdParms[9].Value = model.MemPoint;
            cmdParms[10].Value = model.MemMoney;
            cmdParms[11].Value = model.MemEmail;
            cmdParms[12].Value = model.MemAddress;
            cmdParms[13].Value = model.MemState;
            cmdParms[14].Value = model.MemRecommendID;
            cmdParms[15].Value = model.MemLevelID;
            cmdParms[0x10].Value = model.MemShopID;
            cmdParms[0x11].Value = model.MemCreateTime;
            cmdParms[0x12].Value = model.MemRemark;
            cmdParms[0x13].Value = model.MemConsumeMoney;
            cmdParms[20].Value = model.MemUserID;
            cmdParms[0x15].Value = model.MemTelePhone;
            cmdParms[0x16].Value = model.MemProvince;
            cmdParms[0x17].Value = model.MemCity;
            cmdParms[0x18].Value = model.MemCounty;
            cmdParms[0x19].Value = model.MemVillage;
            cmdParms[0x1a].Value = model.MemQuestion;
            cmdParms[0x1b].Value = model.MemAnswer;
            cmdParms[0x1c].Value = model.MemWeiXinCard;
            cmdParms[0x1d].Value = model.MemCardNumber;
            cmdParms[30].Value = model.MemWeiXinCards;
            cmdParms[0x1f].Value = model.MemAttention;
            cmdParms[0x20].Value = model.MemID;
            int num = DbHelperSQL.ExecuteSql(builder.ToString(), cmdParms);
            if (num > 0)
            {
                return num;
            }
            return 0;
        }

        public void UpdateLevel(int memID, int levelID)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(" update Mem set MemLevelID =@MemLevelID ");
            builder.Append(" where MemID=@MemID");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@MemLevelID", SqlDbType.Int, 4), new SqlParameter("@MemID", SqlDbType.Int, 4) };
            cmdParms[0].Value = levelID;
            cmdParms[1].Value = memID;
            DbHelperSQL.ExecuteSql(builder.ToString(), cmdParms);
        }

        public int UpdateMemPastTime(int memID, DateTime pastTime)
        {
            StringBuilder builder = new StringBuilder();
            if (this.GetModel(memID).MemIsPast)
            {
                builder.Append(" update Mem set MemPastTime =@MemPastTime,");
                builder.Append(" MemIsPast=0");
                builder.Append(" where MemID=@MemID");
                SqlParameter[] parameterArray = new SqlParameter[] { new SqlParameter("@MemPastTime", SqlDbType.DateTime), new SqlParameter("@MemID", SqlDbType.Int, 4) };
                parameterArray[0].Value = pastTime;
                parameterArray[1].Value = memID;
                return DbHelperSQL.ExecuteSql(builder.ToString(), parameterArray);
            }
            builder.Append(" update Mem set MemPastTime =@MemPastTime");
            builder.Append(" where MemID=@MemID");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@MemPastTime", SqlDbType.DateTime), new SqlParameter("@MemID", SqlDbType.Int, 4) };
            cmdParms[0].Value = pastTime;
            cmdParms[1].Value = memID;
            return DbHelperSQL.ExecuteSql(builder.ToString(), cmdParms);
        }

        public int UpdateMemPwd(int memID, string newPwd)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(" update Mem set MemPassword=@MemPassword ");
            builder.Append(" where MemID=@MemID");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@MemPassword", SqlDbType.VarChar, 50), new SqlParameter("@MemID", SqlDbType.Int, 4) };
            cmdParms[0].Value = newPwd;
            cmdParms[1].Value = memID;
            return DbHelperSQL.ExecuteSql(builder.ToString(), cmdParms);
        }

        public int UpdateMemSelf(Chain.Model.Mem model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("update Mem set ");
            builder.Append("MemIdentityCard=@MemIdentityCard,");
            builder.Append("MemMobile=@MemMobile,");
            builder.Append("MemBirthday=@MemBirthday,");
            builder.Append("MemMoney=@MemMoney,");
            builder.Append("MemEmail=@MemEmail,");
            builder.Append("MemAddress=@MemAddress,");
            builder.Append("MemRecommendID=@MemRecommendID,");
            builder.Append("MemRemark=@MemRemark,");
            builder.Append("MemTelePhone=@MemTelePhone ");
            builder.Append(" where MemID=@MemID");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@MemIdentityCard", SqlDbType.VarChar, 50), new SqlParameter("@MemMobile", SqlDbType.VarChar, 50), new SqlParameter("@MemBirthday", SqlDbType.DateTime), new SqlParameter("@MemMoney", SqlDbType.Money, 8), new SqlParameter("@MemEmail", SqlDbType.VarChar, 50), new SqlParameter("@MemAddress", SqlDbType.NVarChar, 200), new SqlParameter("@MemRecommendID", SqlDbType.Int, 4), new SqlParameter("@MemRemark", SqlDbType.NVarChar, 500), new SqlParameter("@MemTelePhone", SqlDbType.VarChar, 50), new SqlParameter("@MemID", SqlDbType.Int, 4) };
            cmdParms[0].Value = model.MemIdentityCard;
            cmdParms[1].Value = model.MemMobile;
            cmdParms[2].Value = model.MemBirthday;
            cmdParms[3].Value = model.MemMoney;
            cmdParms[4].Value = model.MemEmail;
            cmdParms[5].Value = model.MemAddress;
            cmdParms[6].Value = model.MemRecommendID;
            cmdParms[7].Value = model.MemRemark;
            cmdParms[8].Value = model.MemTelePhone;
            cmdParms[9].Value = model.MemID;
            int num = DbHelperSQL.ExecuteSql(builder.ToString(), cmdParms);
            if (num > 0)
            {
                return num;
            }
            return 0;
        }

        public int UpdateMemState(int memID, int state)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(" update Mem set MemState=@MemState ");
            builder.Append(" where MemID=@MemID");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@MemState", SqlDbType.Int, 4), new SqlParameter("@MemID", SqlDbType.Int, 4) };
            cmdParms[0].Value = state;
            cmdParms[1].Value = memID;
            return DbHelperSQL.ExecuteSql(builder.ToString(), cmdParms);
        }

        public int updateMemSyaArea(string strProvince, string strCity, string strCounty, string strVillage, int memId)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(" Update Mem set ");
            builder.Append(" MemProvince=@MemProvince,");
            builder.Append(" MemCity=@MemCity,");
            builder.Append(" MemCounty=@MemCounty,");
            builder.Append(" MemVillage=@MemVillage");
            builder.Append(" where MemID=@MemID");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@MemProvince", SqlDbType.VarChar, 50), new SqlParameter("@MemCity", SqlDbType.VarChar, 50), new SqlParameter("@MemCounty", SqlDbType.VarChar, 50), new SqlParameter("@MemVillage", SqlDbType.VarChar, 50), new SqlParameter("@MemID", SqlDbType.Int, 4) };
            cmdParms[0].Value = strProvince;
            cmdParms[1].Value = strCity;
            cmdParms[2].Value = strCounty;
            cmdParms[3].Value = strVillage;
            cmdParms[4].Value = memId;
            return DbHelperSQL.ExecuteSql(builder.ToString(), cmdParms);
        }

        public int UpdateMoney(decimal money, int memID)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(" update Mem set MemMoney = MemMoney+@MemMoney ");
            builder.Append(" where MemID=@MemID ");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@MemMoney", SqlDbType.Money, 8), new SqlParameter("@MemID", SqlDbType.Int, 4) };
            cmdParms[0].Value = money;
            cmdParms[1].Value = memID;
            return DbHelperSQL.ExecuteSql(builder.ToString(), cmdParms);
        }

        public int UpdatePoint(int memID, int point)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(" update Mem set MemPoint = MemPoint+@MemPoint ");
            builder.Append(" where MemID =@MemID ");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@MemPoint", SqlDbType.Int, 4), new SqlParameter("@MemID", SqlDbType.Int, 4) };
            cmdParms[0].Value = point;
            cmdParms[1].Value = memID;
            return DbHelperSQL.ExecuteSql(builder.ToString(), cmdParms);
        }

        public DataSet WeiXinLogin(string WeiXinCard, string PassWord)
        {
            DataSet set = DbHelperSQL.Query(string.Format("select *  from mem  where (MemWeiXinCard='{0}' or MemCard='{0}' or MemMobile='{0}') and MemPassword='{1}'", WeiXinCard, PassWord));
            if (set.Tables[0].Rows.Count > 0)
            {
                return set;
            }
            return null;
        }

        public int WeiXinRegister(string MemName, string PassWord, string telnumber, string referrerMemId, string memWeiXinCard, int MemShopID, string hidtf)
        {
            if (DbHelperSQL.Query(string.Format("select MemMobile from mem where MemMobile='{0}'", telnumber)).Tables[0].Rows.Count > 0)
            {
                return -1;
            }
            DateTime now = DateTime.Now;
            string sQLString = string.Format("insert  into mem (MemCard,MemName, MemPassword, MemMobile,MemBirthday,MemState,MemRecommendID,MemLevelID,MemShopID,MemCreateTime,MemUserID,MemPastTime,MemWeiXinCard,MemWeiXinCards,MemAttention) values ('{0}','{1}','{2}','{3}','1900/1/1 0:00:00',0,'{4}',0,{7},'{5}',1,'2900/1/1 0:00:00','{6}','{6}',1)", new object[] { telnumber, MemName, PassWord, telnumber, referrerMemId, now, memWeiXinCard, MemShopID });
            if (hidtf == "0")
            {
                sQLString = string.Format("insert  into mem (MemCard,MemName, MemPassword, MemMobile,MemBirthday,MemState,MemRecommendID,MemLevelID,MemShopID,MemCreateTime,MemUserID,MemPastTime,MemWeiXinCard,MemWeiXinCards,MemAttention) values ('{0}','{1}','{2}','{3}','1900/1/1 0:00:00',0,'{4}',0,{7},'{5}',1,'2900/1/1 0:00:00','{6}','{6}',1)", new object[] { telnumber, MemName, PassWord, telnumber, referrerMemId, now, memWeiXinCard, MemShopID });
            }
            else
            {
                sQLString = string.Format("insert  into mem (MemCard,MemName, MemPassword, MemMobile,MemBirthday,MemState,MemRecommendID,MemLevelID,MemShopID,MemCreateTime,MemUserID,MemPastTime,MemWeiXinCard,MemWeiXinCards,MemAttention) values ('{0}','{1}','{2}','{3}','1900/1/1 0:00:00',0,'{4}',0,{7},'{5}',1,'2900/1/1 0:00:00','{6}','{6}',2)", new object[] { telnumber, MemName, PassWord, telnumber, referrerMemId, now, memWeiXinCard, MemShopID });
            }
            string str3 = string.Format("select MemID from mem where MemMobile='{0}' and MemPassword='{1}'", telnumber, PassWord);
            if (DbHelperSQL.ExecuteSql(sQLString) > 0)
            {
                return Convert.ToInt32(DbHelperSQL.Query(str3).Tables[0].Rows[0]["MemID"]);
            }
            return -2;
        }
    }
}

